from django.db import models
from django.forms import ModelForm
from openpolitics.models import Person, Elections

from datetime import date

class Status(models.Model):
    name = models.CharField(max_length=50)
    # slug = models.SlugField()

    class Meta:
        ordering = ('id',)
        verbose_name_plural = 'Statuses'

    def __unicode__(self):
        return self.name

#declaration?
class Promise(models.Model):
    person = models.ForeignKey(Person, related_name='promises')
    elections = models.ForeignKey(Elections, blank=True, null=True)
    date = models.DateField(null=True, blank=True, default=date.today())
    name = models.CharField(max_length=150, blank=True)
    description = models.TextField(blank=True, null=True)
    verification = models.TextField(blank=True, null=True)
    status = models.ForeignKey(Status, default=1)

    def __unicode__(self):
        return '(%s) %s' % (self.person.name, self.name)

class PromiseForm(ModelForm):
    class Meta:
        model = Promise
        fields = ('person', 'elections', 'name', 'description', 'verification')

class Log(models.Model):
    promise = models.ForeignKey(Promise, related_name='logs')
    date = models.DateField(default=date.today())
    description = models.TextField(blank=True, null=True)
    status = models.ForeignKey(Status, default=1)

    class Meta:
        ordering = ('-date', '-id',)

    def __unicode__(self):
        return 'Update on %s (%s, %s)' % (self.promise.name, self.date, self.status.name)

class LogForm(ModelForm):
    class Meta:
        model = Log
        fields = ('promise', 'description', 'status')


class DateStats(models.Model):
    date = models.DateField()
    person = models.ForeignKey(Person)
    status = models.ForeignKey(Status)
    value = models.IntegerField()
